﻿<?php
include '../../templates/db/db.php';
	 $select_users='SELECT * FROM users WHERE type!=3 && type!=2';
	 $results_users=mysql_query($select_users);
	
	 while($row_users=mysql_fetch_assoc($results_users)){
	     $S= $_POST[$row_users['username']]." , ".$S;
	 }
	 
	$sel_u = mysql_query('SELECT * FROM users WHERE username="'.$_SESSION['username'].'"');
	$row_u = mysql_fetch_assoc($sel_u);
	$E = $row_u['teacher_to'];
	 
	 $user = $_SESSION['username'];
	 $title = htmlspecialchars(trim(addslashes($_POST['tutorial'])));
	 $names = $S;
	 $tutorial = $E;
	 $date=time();
	
	
	if((strlen($title) < 2)) {
	?>
	<meta http-equiv="refresh" content="0;url=<?php echo '../users.php?mode=first '?>"/>
		<script type='text/javascript'>
			alert('Кратка тема!');
		</script>
		
		<meta http-equiv="refresh" content="0;url=../users.php"/>
	<?php
	}
	else {
	 $ins= 'INSERT INTO groups(`from_who`, `title_group`, `names`, `tutorial`, `date`) 
							VALUES("'.$user.'", "'.$title.'", "'.$names.'", "'.$tutorial.'", "'.$date.'")' or die(mysql_error());
	 $ins_q = mysql_query($ins) or die(mysql_error());
	 ?>
	 
	 <meta http-equiv="refresh" content="0;url=<?php echo '../users.php?mode=first '?>"/>
	 <script type='text/javascript'>
			alert('Успешно записване на група!');
		</script>
	<?php
	}
?>